﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.Generator.LiteralAttributeCodeGenerator
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

using Microsoft.Internal.Web.Utils;
using System.Globalization;
using System.Web.Razor.Parser.SyntaxTree;
using System.Web.Razor.Text;

namespace System.Web.Razor.Generator
{
  /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Represents a code generator for literal attribute.</summary>
  public class LiteralAttributeCodeGenerator : SpanCodeGenerator
  {
    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. . Initializes a new instance of the <see cref="T:System.Web.Razor.Generator.LiteralAttributeCodeGenerator" /> class.</summary>
    /// <param name="prefix">The prefix of the literal attribute.</param>
    /// <param name="valueGenerator">The value generator for the literal attribute.</param>
    public LiteralAttributeCodeGenerator(
      LocationTagged<string> prefix,
      LocationTagged<SpanCodeGenerator> valueGenerator)
    {
      this.Prefix = prefix;
      this.ValueGenerator = valueGenerator;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. . Initializes a new instance of the <see cref="T:System.Web.Razor.Generator.LiteralAttributeCodeGenerator" /> class.</summary>
    /// <param name="prefix">The prefix of the literal attribute.</param>
    /// <param name="value">The value of the literal attribute.</param>
    public LiteralAttributeCodeGenerator(
      LocationTagged<string> prefix,
      LocationTagged<string> value)
    {
      this.Prefix = prefix;
      this.Value = value;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Gets or sets the prefix of the literal attribute.</summary>
    /// <returns>The prefix of the literal attribute.</returns>
    public LocationTagged<string> Prefix { get; private set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Gets or sets the value of the literal attribute.</summary>
    /// <returns>The value of the literal attribute.</returns>
    public LocationTagged<string> Value { get; private set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Gets or sets the value generator for the literal attribute.</summary>
    /// <returns>The value generator for the literal attribute.</returns>
    public LocationTagged<SpanCodeGenerator> ValueGenerator { get; private set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Generates the code for the literal attribute.</summary>
    /// <param name="target">The source span whose content represents the literal attribute.</param>
    /// <param name="context">The context of the code generator.</param>
    public override void GenerateCode(Span target, CodeGeneratorContext context)
    {
      if (context.Host.DesignTimeMode)
        return;
      ExpressionRenderingMode expressionRenderingMode = context.ExpressionRenderingMode;
      context.BufferStatementFragment(context.BuildCodeString((Action<CodeWriter>) (cw =>
      {
        cw.WriteParameterSeparator();
        cw.WriteStartMethodInvoke("Tuple.Create");
        cw.WriteLocationTaggedString(this.Prefix);
        cw.WriteParameterSeparator();
        if (this.ValueGenerator != (LocationTagged<SpanCodeGenerator>) null)
        {
          cw.WriteStartMethodInvoke("Tuple.Create", "System.Object", "System.Int32");
          context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode;
        }
        else
        {
          cw.WriteLocationTaggedString(this.Value);
          cw.WriteParameterSeparator();
          cw.WriteBooleanLiteral(true);
          cw.WriteEndMethodInvoke();
          cw.WriteLineContinuation();
        }
      })));
      if (this.ValueGenerator != (LocationTagged<SpanCodeGenerator>) null)
      {
        this.ValueGenerator.Value.GenerateCode(target, context);
        context.FlushBufferedStatement();
        context.ExpressionRenderingMode = expressionRenderingMode;
        context.AddStatement(context.BuildCodeString((Action<CodeWriter>) (cw =>
        {
          cw.WriteParameterSeparator();
          cw.WriteSnippet(this.ValueGenerator.Location.AbsoluteIndex.ToString((IFormatProvider) CultureInfo.CurrentCulture));
          cw.WriteEndMethodInvoke();
          cw.WriteParameterSeparator();
          cw.WriteBooleanLiteral(false);
          cw.WriteEndMethodInvoke();
          cw.WriteLineContinuation();
        })));
      }
      else
        context.FlushBufferedStatement();
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Returns the string representation of this instance.</summary>
    /// <returns>The string representation of this instance.</returns>
    public override string ToString() => this.ValueGenerator == (LocationTagged<SpanCodeGenerator>) null ? string.Format((IFormatProvider) CultureInfo.CurrentCulture, "LitAttr:{0:F},{1:F}", (object) this.Prefix, (object) this.Value) : string.Format((IFormatProvider) CultureInfo.CurrentCulture, "LitAttr:{0:F},<Sub:{1:F}>", (object) this.Prefix, (object) this.ValueGenerator);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified object is equal to this instance.</summary>
    /// <returns>true if the specified object is equal to this instance; otherwise, false.</returns>
    /// <param name="obj">The object to compare to this instance.</param>
    public override bool Equals(object obj) => obj is LiteralAttributeCodeGenerator attributeCodeGenerator && object.Equals((object) attributeCodeGenerator.Prefix, (object) this.Prefix) && object.Equals((object) attributeCodeGenerator.Value, (object) this.Value) && object.Equals((object) attributeCodeGenerator.ValueGenerator, (object) this.ValueGenerator);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Gets the hash code for the current instance.</summary>
    /// <returns>The hash code for the current instance.</returns>
    public override int GetHashCode() => HashCodeCombiner.Start().Add((object) this.Prefix).Add((object) this.Value).Add((object) this.ValueGenerator).CombinedHash;
  }
}
